<?php
require_once('../../../config.php');
require_once($CFG->libdir . '/adminlib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/local/blackboxsurvey/forms.php");
define('AJAX_SCRIPT', true);

//yeu cau login,sau khi login tu dong chuyen sang trang chu
global $USER;
if ($USER->id == null){
    $SESSION->homepage = true;
    require_login($SITE);
}
if($SESSION->homepage){
    $SESSION->homepage = null;
    redirect( $CFG->wwwroot);
}
//object class
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questions.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/question_choice.php");

$id = optional_param('id',null, PARAM_TEXT);
$path_image = $CFG->wwwroot .'/local/blackboxsurvey/image/';
/* Viet doan code cua ban o day */

//get question detail
$b_ques = new b_questions();
$question = $b_ques->get_question_detail($id);

//add question to array to show
$ques_detail['id'] = $question->id;
$ques_detail['content'] = preg_replace(array('#<p>#', '#</p>#'), '', $question->content, 1);
//$ques_detail['content'] = $question->content;

$mform = new form_edit_question(null, $ques_detail);

//
if ($fromform = $mform->get_data()) 
{	
    //du lieu can cho viec update
    $question['id'] = $fromform->txtid;
    $question['content'] = $fromform->txtcont;
	
    //echo "<script>alert('".$question['id_type']."');</script>";
    
    $update_ques = new b_questions();
    $update_ques->update_question($question);
    
	//close colorbox
	echo "<script>parent.$.fn.colorbox.close(); </script>";
    //echo "<script  type='text/javascript'>question_search_result();</script>";
}


$mform->display();
/*------Ket thuc doan code cua ban-------*/

